<script setup lang="ts">
  import { onLaunch, onShow, onHide } from "@dcloudio/uni-app";
  import { http } from "@/utils/http";
  import { useStore } from 'vuex';
  import { getUserInfo } from "./utils/common";
  const store = useStore();
  onLaunch(() => {
    console.log("App Launch");
    const { loading } = store.state;
    if (loading) return;
    store.commit('changeState', { loading: true })
    uni.login({
      success: async (loginRes) => {
        const { code } = loginRes || {};
        if (code) {
          await http({
            method: 'POST',
            url: '/login/login',
            data: {
              loginCode: code,
            }
          }).then(async (res: any) => {
            if (res.success) {
              const { token } = res.data;
              try {
                uni.setStorageSync('token', token);
                store.commit('changeState', {
                  token,
                })
                await getUserInfo(store);
              } catch (e) {
                uni.$u.toast('登录失败')
              }
            } else {
              uni.$u.toast(res.msg || '登录失败');
            }
          })
        }
        store.commit('changeState', { loading: false });
      },
      fail: () => store.commit('changeState', { loading: false })
    })
  });
  onShow(() => {
    console.log("App Show");
  });
  onHide(() => {
    console.log("App Hide");
  });
</script>
<style>

</style>
<style lang="scss">
  @import "./css/base.scss";
  @for $i from 1 through 5 {
    .u-line-#{$i} {
      /* #ifdef APP-NVUE */
      // nvue下，可以直接使用lines属性，这是weex特有样式
      lines: $i;
      text-overflow: ellipsis;
      overflow: hidden;
      flex: 1;
      /* #endif */

      /* #ifndef APP-NVUE */
      // vue下，单行和多行显示省略号需要单独处理
      @if $i =='1' {
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
      }

      @else {
        display: -webkit-box !important;
        overflow: hidden;
        text-overflow: ellipsis;
        word-break: break-all;
        -webkit-line-clamp: $i;
        -webkit-box-orient: vertical !important;
      }

      /* #endif */
    }
  }
</style>
